package com.cskaoyan.service;

import com.cskaoyan.bean.MarketFeedback;
import com.cskaoyan.bean.MarketUser;
import com.cskaoyan.bean.bo.WxFeedbackSubmitBo;
import com.cskaoyan.mapper.MarketFeedbackMapper;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;


/**
 * @description:
 * @author: Tao
 * @time: 2023/1/3 1:56
 */
@Service
public class WxFeedbackServiceImpl implements WxFeedbackService {

    @Autowired
    MarketFeedbackMapper feedbackMapper;

    /**
     * 应用的反馈功能
     *
     * @param wxFeedbackSubmitBo
     */
    @Override
    public void submit(WxFeedbackSubmitBo wxFeedbackSubmitBo) {
        //获取当前用户的id以及用户名
        Subject subject = SecurityUtils.getSubject();
        MarketUser principal = (MarketUser) subject.getPrincipal();
        Integer userId = principal.getId();
        String username = principal.getUsername();
        //实例化对象
        MarketFeedback marketFeedback = new MarketFeedback();
        marketFeedback.setUserId(userId);
        marketFeedback.setUsername(username);
        marketFeedback.setMobile(wxFeedbackSubmitBo.getMobile());
        marketFeedback.setFeedType(wxFeedbackSubmitBo.getFeedType());
        marketFeedback.setContent(wxFeedbackSubmitBo.getContent());
        marketFeedback.setStatus(0);
        boolean hasPicture = wxFeedbackSubmitBo.isHasPicture();
        marketFeedback.setHasPicture(hasPicture);
        //如果图片不为空则插入
        if (hasPicture) {
            String[] picUrls = wxFeedbackSubmitBo.getPicUrls();
            //封装
            marketFeedback.setPicUrls(picUrls);
        }
        marketFeedback.setAddTime(new Date());
        marketFeedback.setUpdateTime(new Date());
        marketFeedback.setDeleted(false);
        //插入操作
        feedbackMapper.insertSelective(marketFeedback);
    }
}
